$(function () {

    $("#gprsTable table tr").css({ "display": "table-row" });
    $("#brightness input[name='points']").css({ "width": "50px","height":"22px" });
    $("#param input[name='points']").css({ "width": "100px" });


    //$("#devicenumber").val(sessionStorage.getItem("setdevicenumber"));//卡号
    //起始时间 
    // $('.time').clockTimePicker({});


    //扫描按钮触发file上传文件
    $("#scanning").click(function () {
        $("#file").click();
    });
    //获取浏览的文件
    $('#file').change(function () {

    });


    //亮度、时间个数选择
    window.lightchange = function () {
        for (var i = 1; i <= 4; i++) {
            //先全部禁用
            $("#timer"+i).find("input").attr("disabled", true);
            $("#timer" + i).css("color", "gainsboro");

            $("#brightness").find("input[type='number']:eq(" + i + ")").attr("disabled", true);
        }
        for (var i = 1; i <= parseInt($("#timeCount").val()); i++) {
            //根据选择个数来设置
            var ii = parseInt(i) - 1;
             $("#brightness").find("input[type='number']:eq(" + ii + ")").removeAttr("disabled");
            $("#timer" + i).find("input").removeAttr("disabled");;
            $("#timer" + i).css("color", "");

        }
    }

      //开关屏个数选择
      window.screenchange = function () {
        for (var i = 1; i <= 4; i++) {
            //先全部禁用
            $("#stimer"+i).find("input").attr("disabled", true);
            $("#stimer"+i).css("color", "gainsboro");
            $("#etimer"+i).find("input").attr("disabled", true);
            $("#etimer"+i).css("color", "gainsboro");
        }
        for (var i = 1; i <= parseInt($("#timeScreenCount").val()); i++) {
            //根据选择个数来设置
            
            $("#stimer"+ i).find("input").removeAttr("disabled");;
            $("#stimer"+ i).css("color", "");
            $("#etimer"+i).find("input").removeAttr("disabled");;
            $("#etimer"+i).css("color", "");

        }
    }


    //调节方式选择
    $("#lightType").change(function () {

        //0为定时调节，1为自动调节
        if ($(this).val() == "0") {
            $("#timeCount").attr("disabled", false);
            $("#timer1").find("input:eq(0),input:eq(2)").val("00");
           
        } else {
            $("#timeCount").attr("disabled", true);
            $("#timeCount").val("1");
            $("#timer1").find("input").attr("disabled", false);
        }
        lightchange();
    });


    /**基本参数 */
    $("#sup").click(function () {
        
        
        
        if ($("#ledclkmultiple").is(":checked")) {
            $(this).val(0);
           
        }else{
            $(this).val(1);
        }
       
       
        //var jsonval={};
        if ($("#devicenumber").val() == "") {
            swal("OMG!", "请先选择设备", "error");
            return;
        }

        if ($("#param input:first").val() == "") {
            swal("OMG!", "请选择宽度", "error");
            return;
        } if ($("#param input:eq(1)").val() == "") {
            swal("OMG!", "请选择高度", "error");
            return;
        } if ($("#param input:eq(2)").val() == "") {
            swal("OMG!", "请选择节目数量", "error");
            return;
        } if (parseInt($("#param input:eq(2)").val()) < 0 || parseInt($("#param input:eq(2)").val()) > 127) {
            swal("OMG!", "节目数量范围在0~127", "error");
            return;
        }
        
        var rgbcolor=$("#rgbcolor").val();
        var arr=rgbcolor.split(',');
        console.log("颜色"+arr[0]+","+arr[1]+","+arr[2]);
        //扩展参数
        var kuoarr=new Array(0,parseInt(arr[0]),parseInt(arr[1]),parseInt(arr[2]),3,
                            parseInt($("#ledColumnChip").val()),parseInt($("#ledRowChip").val()),4,
                            $("#ledGrayScale").val(),parseInt($("#ledHclkCycle").val()),
                            parseInt($("#ledclkmultiple").val()),
                            parseInt($("#scanHclkDelay").val()),0,
                            parseInt($("#scanBlankingTime").val()),
                            parseInt($("#scanMultParam").val()),parseInt($("#scanDataDirection").val()),
                            parseInt($("#dispalyMSBTimeMult").val())  );
              
                            var jsonval ={};

                  if ($("#yerOrNo").is(":checked")) {

                    if (parseInt($("#scanHclkDelay").val()) < 0 || parseInt($("#scanHclkDelay").val()) > 7) {
                        swal("OMG!", "节目数量范围在0~127", "error");
                        return;
                    }
                    jsonval = {
                        "width": $("#param input:first").val(),
                        "height": $("#param input:eq(1)").val(),
                        "totalProgram": $("#param input:eq(2)").val(),
                        "color": $("#color").val(),
                        "oep": $("#check input:eq(0)").val(),
                        "dap": $("#check input:eq(1)").val(),
                        "nvertedByte": $("#check input:eq(2)").val(),
                        "sync": 0,
                        "warning": 0,
                        "sms": 0,
                        "extend":kuoarr
                    };
                               
                    }else{
                        jsonval = {
                            "width": $("#param input:first").val(),
                            "height": $("#param input:eq(1)").val(),
                            "totalProgram": $("#param input:eq(2)").val(),
                            "color": $("#color").val(),
                            "oep": $("#check input:eq(0)").val(),
                            "dap": $("#check input:eq(1)").val(),
                            "nvertedByte": $("#check input:eq(2)").val(),
                            "sync": 0,
                            "warning": 0,
                            "sms": 0
                        };      
                     }
        console.log("你"+JSON.stringify(jsonval))
       $("body").mLoading("show");
        $.ajax({
            type: "post",
            url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
            dataType: "text",
            timeout: 15000,//超时设置
            data: {
                "sessionid": sessionStorage.getItem("sid"), "cmd": 21, "devicenumber": $("#devicenumber").val(),
                "deviceType": sessionStorage.getItem("type"), "companyId": sessionStorage.getItem("coid"),
                "json": JSON.stringify(jsonval)
            },

            success: function (data) {
                data = JSON.parse(data);
                if (data.code == "200") {
                    $("body").mLoading("hide");
                    swal("success!", "成功", "success");
                } else {
                    $("body").mLoading("hide");
                    swal("OMG!", "设置失败", "error");
                }
            },error: function (response, ajaxOptions, thrownError) {
           
                $(".mloading-mask").hide();
                swal("OMG!", "设置失败", "error");
            },
        });
    });


    /**单击音量设置 */
    $("#volume").click(function () {
        if ($("#devicenumber").val() == "") {
            swal("OMG!", "请先选择设备", "error");
            return;
        }

        if (($("#VolumnValue").val()) < 1 || ($("#VolumnValue").val()) > 10) {
            swal("OMG!", "音量的范围在1~10之内", "error");
            return;
        }
        var jsonval = new Array();
        jsonval.push(
            {
                "beginTime": "00:00",
                "volumnValue": $("#VolumnValue").val()

            }
        );
        //  alert(jsonval);
        $("body").mLoading("show");
        $.ajax({
            type: "post",
            url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
            dataType: "text",
            timeout: 15000,//超时设置
            data: {
                "sessionid": sessionStorage.getItem("sid"), "cmd": 131, "devicenumber": $("#devicenumber").val(),
                "deviceType": sessionStorage.getItem("type"), "companyId": sessionStorage.getItem("coid"), "volumnType": 1, "json": JSON.stringify(jsonval)
            },
            success: function (data) {

                data = JSON.parse(data);
                if (data.code == "200") {
                    $("body").mLoading("hide");
                    swal("success!", "成功", "success");
                } else {
                    $("body").mLoading("hide");
                    swal("OMG!", "设置失败", "error");
                }
            },error: function (response, ajaxOptions, thrownError) {
           
                $(".mloading-mask").hide();
                swal("OMG!", "设置失败", "error");
            },
        });

    });


    /**调节亮度 */
    $("#light").click(function () {

        if ($("#devicenumber").val() == "") {
            swal("OMG!", "请先选择设备", "error");
            return;
        }

        //提示亮度值范围
        var lights = $("#brightness input[type='number']").val();
        if (lights == "") {
            swal("OMG!", "亮度值不为空，请重新填写", "error");
            return;
        }
        if (lights < 0 || lights > 15) {
            swal("OMG!", "亮度值的范围是0~15，请重新填写", "error");
            return;
        }

        var jsonval = new Array();

        //取时间的值
         var time = "";
         var timeArr=['']; 
             for (var i = 0; i < $("#timeCount").val(); i++) {
                var ii = parseInt(i) + 1;
                time = "";//到下一轮清空
                $("#timer" + ii).find("input[type='text']").each(function (i) {
    
                    time +=$(this).val();
                });
                if ($("#lightType").val() == "1") {
                    time = "00:00";
                }
 
             timeArr[i]=time;
            if(i>=1){
             i
             if (getNowFormatDate()+ " " + timeArr[i] <= getNowFormatDate()+ " " + timeArr[i-1]){
 
                 swal("error!", "第"+(i+1)+"个时间值不能小于或等于上一个时间！", "error");
                 return false;
             }
             
         }
            jsonval.push({
                "lightBeginTime": timeArr[i],
                "lightValue": $("#brightness").find("input[type='number']:eq(" + i + ")").val()

            });
            console.log(JSON.stringify(jsonval));

        }

        $("body").mLoading("show");
        $.ajax({
            type: "post",
            url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
            dataType: "text",
            timeout: 15000,//超时设置
            data: {
                "sessionid": sessionStorage.getItem("sid"), "cmd": 28, "devicenumber": $("#devicenumber").val(),
                "deviceType": sessionStorage.getItem("type"), "companyId": sessionStorage.getItem("coid"), "lightType": parseInt($("#lightType").val()),
                "json": JSON.stringify(jsonval)
            },

            success: function (data) {
                data = JSON.parse(data);
                if (data.code == "200") {
                    $("body").mLoading("hide");
                    swal("success!", "成功", "success");
                } else {
                    $("body").mLoading("hide");
                    swal("OMG!", "设置失败", "error");
                }
            },error: function (response, ajaxOptions, thrownError) {
           
                $(".mloading-mask").hide();
                swal("OMG!", "设置失败", "error");
               },
        });


    });


    /**设置GPRS通信**/
    $("#GPRS").click(function () {
        if ($("#devicenumber").val() == "") {
            swal("OMG!", "请先选择设备", "error");
            return;
        }
        if($("#ip").val()!=""){
        if (isValidIP($("#ip").val()) == false) {
            swal("OMG!", "IP格式不正确", "error");
            return;
        }
    }
        if (parseInt($("#port").val()) < 4000 || parseInt($("#port").val()) > 65536) {
            swal("OMG!", "此端口无效！", "error");
            return;
        }


        var jsonval = {
            "apn": $("#APN").val(),
            "userName": $("#userName").val(),
            "password": $("#userPwd").val(),
            "dns": $("#DNS").val(),
            "domain": $("#ip").val(),
            "port": $("#port").val(),
            "ipType": $("#ipType").val(),
            "is4G": $("#is4G").val()

        };
        $("body").mLoading("show");
        $.ajax({
            type: "post",
            url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
            dataType: "text",
            timeout: 15000,//超时设置
            data: {
                "sessionid": sessionStorage.getItem("sid"), "cmd": 52, "devicenumber": $("#devicenumber").val(),
                "deviceType": sessionStorage.getItem("type"), "companyId": sessionStorage.getItem("coid"),
                "json": JSON.stringify(jsonval)
            },

            success: function (data) {
                data = JSON.parse(data);

                if (data.code == "200") {
                    $("body").mLoading("hide");
                    swal("success!", "成功", "success");
                } else {
                    // alert(123);
                    $("body").mLoading("hide");
                    swal("OMG!", "设置失败", "error");
                }
            },error: function (response, ajaxOptions, thrownError) {
           
                    $(".mloading-mask").hide();
                    swal("OMG!", "设置失败", "error");
            },
        });
    });


    /**回读基本参数**/
    $("#readParam").click(function () {

        if ($("#devicenumber").val() == "") {
            swal("OMG!", "请先选择设备！", "error");
            return;
        }

        var devicenumber = $("#devicenumber").val();
        if (devicenumber.length > 12) {
            swal("OMG!", "只能回读一个卡号", "error");

        } else {
            $.fn.jqLoading({ height: 100, width: 240, text: "正在读取中，请耐心等待...." });
            $.ajax({
                type: "post",
                url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
                dataType: "text",
                timeout: 15000,//超时设置
                data: {
                    "sessionid": sessionStorage.getItem("sid"), "cmd": 30, "devicenumber": $("#devicenumber").val(),
                    "deviceType": sessionStorage.getItem("type"), "companyId": sessionStorage.getItem("coid")

                },
                success: function (data) {

                    $.fn.jqLoading("destroy");
                    data = JSON.parse(data);
                    console.log(data);
                    if (data != "") {

                        if (data.status == "error") {
                            swal("OMG!", "回读失败,卡号不在线！", "error");
                        } else {

                            swal("success!", "成功", "success");
                            $("#param input:first").val(data.RowPointNum);
                            $("#param input:eq(1)").val(data.ColPointNum);
                            $("#param input:eq(2)").val(data.ProgramTotal);

                            var maxIndex = $("#color option:last").val();//获取select最大的索引
                            for (var i = 0; i < maxIndex; i++) {
                                $("#color option[value='" + data.Color + "']").attr("selected", "selected");//值匹配对的，设为选中

                            }
                        }

                    } else {
                        swal("OMG!", "回读失败", "error");
                    }

                }
            });
        }
    });

    /**回读GPRS通信**/
    $("#readGPRS").click(function () {
        if ($("#devicenumber").val() == "") {
            swal("OMG!", "请先选择设备！", "error");
            return;
        }
        if (($("#devicenumber").val()).length > 12) {
            swal("OMG!", "只能回读一个卡号", "error");
            return;
        }
        $.fn.jqLoading({ height: 100, width: 240, text: "正在读取中，请耐心等待...." });
        $.ajax({
            type: "post",
            url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
            dataType: "text",
            timeout: 15000,//超时设置
            data: {
                "sessionid": sessionStorage.getItem("sid"), "cmd": 63, "devicenumber": $("#devicenumber").val(),
                "deviceType": sessionStorage.getItem("type"), "companyId": sessionStorage.getItem("coid")
            },

            success: function (data) {
                console.log(data);
                // data = JSON.parse(data);
                $.fn.jqLoading("destroy");
                data = eval("(" + data + ")");   //转json格式
                //alert(data.IP_Type);
                if (data != "") {
                    if (data.status == "error") {
                        swal("OMG!", "回读失败,卡号不在线！", "error");
                    } else {
                        swal("success!", "成功", "success");
                        //{"IP_Type":"1","IP":"","Port":"6669","USERNAME":"","USERPWD":"","DNS":"lgsv2019.tpddns.cn","is4G":"1","APN":"cmiot"}
                        $("#APN").val(data.APN);
                        $("#userName").val(data.USERNAME);
                        $("#userPwd").val(data.USERPWD);
                        $("#DNS").val(data.DNS);
                        $("#ip").val(data.IP);
                        $("#port").val(data.Port);

                        // 
                        $("#ipType").val(data.IP_Type);

                        if (data.is4G == "1") {
                            $("#is4G").attr("checked", true);
                            $("#is4G").val("1");
                        }
                        if (data.DNS != "") {
                            $("#DNS").attr("readonly", false);
                            $("#ip").attr("readonly", true);

                        } else {
                            $("#DNS").attr("readonly", true);
                            $("#ip").attr("readonly", false);

                        }

                    }

                } else {
                    swal("OMG!", "回读失败", "error");
                }

            }
        });





    });



});

//选择设备(获取卡号)
$(function () {
    $("#choseYes").click(function () {

        $("#devicenumber").val($("#device_id").val());
        $(".close").click();

    });

});



//选择固定IP还是域名来显示默认值
$(function () {

    $("#ipType").click(function () {

        if ($("#ipType").val() == "0") {
            $("#DNS").attr("readonly", true);
            $("#ip").attr("readonly", false);
            $("#DNS").val("");

        } else {
            $("#DNS").attr("readonly", false);
            $("#ip").val("");
            $("#ip").attr("readonly", true);
            $("#port").val("");
        }

    });

    $("#ip").blur(function () {
        //根据ip默认显示端口
        if ($("#ip").val() == "119.23.148.39") {
            $("#port").val("9008");
        }
    });
});


//ip格式
function isValidIP(ip) {
    var reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
    return reg.test(ip);
}


//基本参数复选框的值
window.Choice = function (obj) {
    if ($(obj).val() == "0") {
        $(obj).val(1)
    } else {
        $(obj).val(0);
    }
}

$(function () {

    /**波特率 */
    $("#cuanSet").click(function () {
        if ($("#devicenumber").val() == "") {
            swal("OMG!", "请先选择设备！", "error");
            return;
        }

        if ($("#p_Adrr").val() == "") {
            swal("OMG!", "请选择通信地址！", "error");
            return;
        }

        //提示等待时间范围
        var waitTime = $("#waitTime").val();
        if (waitTime == "") {
            swal("OMG!", "请选择等待时间！", "error");
            return;
        }
        if (waitTime < 1 || waitTime > 15) {
            swal("OMG!", "等待时间的范围是1~15，请重新填写", "error");
            return;
        }


        var jsonval = {
            "address": $("#p_Adrr").val(),
            "baudRate": $("#baudRate").val(),
            "waitTime": $("#waitTime").val()
        };

        $("body").mLoading("show");
        $.ajax({
            type: "post",
            url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
            dataType: "text",
            timeout: 15000,//超时设置
            data: {
                "sessionid": sessionStorage.getItem("sid"), "cmd": 48, "devicenumber": $("#devicenumber").val(),
                "deviceType": sessionStorage.getItem("type"), "companyId": sessionStorage.getItem("coid"), "json": JSON.stringify(jsonval)
            },
            success: function (data) {

                data = JSON.parse(data);
                if (data.code == "200") {
                    $("body").mLoading("hide");
                    swal("success!", "成功", "success");
                } else {
                    $("body").mLoading("hide");
                    swal("OMG!", "设置失败", "error");
                }
            },error: function (response, ajaxOptions, thrownError) {
           
                $(".mloading-mask").hide();
                swal("OMG!", "设置失败", "error");
               },
        });

    });


    //继电器
    $("#bagSet").click(function () {
        if ($("#devicenumber").val() == "") {
            swal("OMG!", "请先选择设备！", "error");
            return;
        }

        var jsonval = {
            "BagID": 0,
            "Offset": 0
        };


        //  alert(jsonval);
        $("body").mLoading("show");
        $.ajax({
            type: "post",
            url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
            dataType: "text",
            timeout: 15000,//超时设置
            data: {
                "sessionid": sessionStorage.getItem("sid"), "cmd": 160, "devicenumber": $("#devicenumber").val(),
                "deviceType": sessionStorage.getItem("type"), "companyId": sessionStorage.getItem("coid"), "json": JSON.stringify(jsonval)
            },
            success: function (data) {

                data = JSON.parse(data);
                if (data.code == "200") {
                    $("body").mLoading("hide");
                    swal("success!", "成功", "success");
                } else {
                    $("body").mLoading("hide");
                    swal("OMG!", "设置失败", "error");
                }
            },error: function (response, ajaxOptions, thrownError) {
           
                $(".mloading-mask").hide();
                swal("OMG!", "设置失败", "error");
            },
        });

    });

    //扫描配置
    $("#scanSet").click(function () {
        if ($("#devicenumber").val() == "") {
            swal("OMG!", "请先选择设备！", "error");
            return;
        }

        var jsonval = {
            "rowOrder": $("#rowOrder").val(),
            "pointFreq": 0,
            "lineShadow": $("#lineShadow").val(),
            "rgOrder": $("#RGOrder").val(),
            "mirror": $("#mirror").val(),
            "decoding": $("#have138").val(),
            "scanType": $("#scanType").val()

        };


        //  alert(jsonval);
        $("body").mLoading("show");
        $.ajax({
            type: "post",
            url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
            dataType: "text",
            timeout: 15000,//超时设置
            data: {
                "sessionid": sessionStorage.getItem("sid"), "cmd": 16, "devicenumber": $("#devicenumber").val(),
                "deviceType": sessionStorage.getItem("type"), "companyId": sessionStorage.getItem("coid"), "json": JSON.stringify(jsonval)
            },
            success: function (data) {

                data = JSON.parse(data);
                if (data.code == "200") {
                    $("body").mLoading("hide");
                    swal("success!", "成功", "success");
                } else {
                    $("body").mLoading("hide");
                    swal("OMG!", "设置失败", "error");
                }
            },error: function (response, ajaxOptions, thrownError) {
           
                $(".mloading-mask").hide();
                swal("OMG!", "设置失败", "error");
            },
        });

    });

});



//上传文件
var fileId = "";

window.fileload = function () {
    var file = $("#file1")[0].files[0];
    var suffix = file.name.split('.');
    if (!/(bin|BIN)$/.test(suffix)) {
        swal("OMG!", "固件格式不正确，请重新输入", "error");
        $("#file1").val("");
        return false;
    }

    var reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onload = function (e) {

        var formData = new FormData();
        formData.append('file', $("#file1")[0].files[0]);
        $.ajax({
            url: domain.testUrl +"/Threeinjection/programManagement/FTPupload?coId="+sessionStorage.getItem("coid"),
            type: 'POST',
            cache: false,
            data: formData,
            processData: false,
            contentType: false,
            success: function (data) {
                data = JSON.parse(data);
                if (data.code == "200") {
                    fileId = data.fileId;
                    // swal("success!", "", "success");
                } else {
                    // swal("OMG!", "设置失败", "error");
                }
            }
        });

    }
}



$(function () {
    //升级固件
    $('#send').click(function () {

        if ($("#devicenumber").val() == "") {
            swal("OMG!", "请先选择设备！", "error");
            return;
        }

        if (fileId == "") {
            swal("OMG!", "上传文件不能为空！", "error");
            return;
        }


        
        $("body").mLoading("show");
        
        $.ajax({
            url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
            type: 'POST',
            timeout: 15000,//超时设置
            data: {
                "sessionid": sessionStorage.getItem("sid"), "cmd": 65, "devicenumber": $("#devicenumber").val(),
                "deviceType": sessionStorage.getItem("type"), "companyId": sessionStorage.getItem("coid"), "fileId": fileId
            },
            success: function (data) {
                data = JSON.parse(data);
                if (data.code == "200") {
                    $("body").mLoading("hide");
                    swal("success!", "设置成功", "success");
                } else {
                    $("body").mLoading("hide");
                    swal("OMG!", "设置失败", "error");
                }
            },error: function (response, ajaxOptions, thrownError) {
           
                $(".mloading-mask").hide();
                swal("OMG!", "设置失败", "error");
            },
        });

    });

    //扫描方式
    seleScanMode();

    //执行操作
    $("#control").click(function () {
        if ($("#devicenumber").val() == "") {
            swal("OMG!", "请先选择设备", "error");
            return;
        }
        //console.log("值" + parseInt($("#option").val()));
        $("body").mLoading("show");
        $.ajax({
            type: "post",
            url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
            dataType: "text",
            timeout: 15000,//超时设置
            data: {
                "sessionid": sessionStorage.getItem("sid"), "cmd":parseInt($("#option").val()), "devicenumber": $("#devicenumber").val(),
                "deviceType": sessionStorage.getItem("type"), "companyId": sessionStorage.getItem("coid")       
            },

            success: function (data) {
                data = JSON.parse(data);

                if (data.code == "200") {
                    $("body").mLoading("hide");
                    swal("success!", "成功", "success");
                    
                } else {
                    $("body").mLoading("hide");
                    swal("OMG!", "设置失败", "error");
                }
            },error: function (response, ajaxOptions, thrownError) {
           
                $(".mloading-mask").hide();
                swal("OMG!", "设置失败", "error");
            },
        });
    });

    //开关屏
      $("#setOption").click(function () {

        if ($("#devicenumber").val() == "") {
            swal("OMG!", "请先选择设备", "error");
            return;
        }

        var jsonval = new Array();

        //取时间的值
        var stime = "";var etime = "";
        var sArr=['']; var eArr=[''];
       
        for (var i = 0; i < $("#timeScreenCount").val(); i++) {
            var ii = parseInt(i) + 1;
            stime = "";//到下一轮清空
            etime = "";
            $("#stimer" + ii).find("input[type='text']").each(function (i) {
                stime += $(this).val();       
            });
            $("#etimer"+ii).find("input[type='text']").each(function (i) {
                etime += $(this).val();
            });

            sArr[i]=stime;
            eArr[i]=etime;

            if(getNowFormatDate()+ " " + sArr[i] >= getNowFormatDate()+ " " + eArr[i]){

                swal("error!","开始时间不能大于或等于结束时间！", "error");
                return false;
            }
           if(i>=1){
            if(getNowFormatDate()+ " " + sArr[i] <= getNowFormatDate()+ " " + eArr[i-1]){

                swal("error!","第"+ii+"个开始时间不能小于或等于上一个结束时间！", "error");
                return false;
            }
            if (getNowFormatDate()+ " " + sArr[i] <= getNowFormatDate()+ " " + sArr[i-1]){

                swal("error!", "第"+ii+"个时间段不能小于或等于上一个时间段！", "error");
                return false;
            }
            if (getNowFormatDate()+ " " + eArr[i] <= getNowFormatDate()+ " " + eArr[i-1]){
                //console.log("mj"+eArr[i])
                swal("error!", "第"+ii+"个时间段不能小于或等于上一个时间段！", "error");
                return false;
            }
            
        }
            jsonval.push({"start":sArr[i],"end":eArr[i]});
            console.log("开关屏"+JSON.stringify(jsonval));
           
        }

        $("body").mLoading("show");
        $.ajax({
            type: "post",
            url: domain.testUrl + "/Threeinjection/DeviceManagement/deviceCommand",
            dataType: "text",
            timeout: 15000,//超时设置
            data: {
                "sessionid": sessionStorage.getItem("sid"), "cmd": 23, "devicenumber": $("#devicenumber").val(),
                "deviceType": sessionStorage.getItem("type"), "companyId": sessionStorage.getItem("coid"),
                "json": JSON.stringify(jsonval)
            },

            success: function (data) {
                data = JSON.parse(data);
                if (data.code == "200") {
                    $("body").mLoading("hide");
                    swal("success!", "成功", "success");
                } else {
                        $("body").mLoading("hide");
                    swal("OMG!", "设置失败", "error");
                }
            },error: function (response, ajaxOptions, thrownError) {
           
            $(".mloading-mask").hide();
            swal("OMG!", "设置失败", "error");
        },
        });


     });

     
});


//扫描方式
window.seleScanMode = function () {

    $.ajax({
        type: "post",
        url: domain.testUrl + "/Threeinjection/DeviceManagement/queryScanModeInfo",
        dataType: "text",
        timeout: 1500,//超时设置
        data: { "sessionid": sessionStorage.getItem("sid") },
        success: function (data) {
            var data2 = JSON.parse(data);
            var arr = data2.ScanModeInfo;//json数组
            if (arr != "" || arr != null) {
                for (var i = 0; i < arr.length; i++) {
                    $("#scanType").append("<option value=" + arr[i].scanType + arr[i].subscanType + ">" + arr[i].scanName + "</option>");

                }
                console.log("扫描方式获取成功！");

            } else {
                $("#scanType").append("<option>无</option>");
            }

        }
    });
}

//日期（时间需要加日期一起）
function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
      month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
      strDate = "0" + strDate;
    }
    var currentdate = year + seperator1 + month + seperator1 + strDate;
    return currentdate;
  }
